# 005-选考A-降水量变化-201604-16学考选考，shell版

import tkinter as tk
from tkinter.constants import N
from tkinter.font import nametofont
from typing import Counter

def findMax():
    # 输入
    wlst = list(map(int,txt1.get().split(',')))
    if not wlst:
        print('输入有误，使用默认数据.')
        wlst = [1,11,19,18,0,16,8,9,17,4]
    #txt1.insert(0, ','.join([str(x) for x in wlst]))

    #处理，找相邻两数差值最大
    imax=1 
    n=len(wlst)
    for i in range(2,n):
        if abs(wlst[i]-wlst[i-1])>=abs(wlst[imax]-wlst[imax-1]):
            imax = i
    #print("年平均降水量变化最大的年份区间是",imax+1899,imax+1900)
    txt2.select_clear()
    txt2.insert(0,'{}-{}'.format(imax+1899, imax+1900))
    

# 建立窗口
win = tk.Tk()
win.title('找最大值')
win.resizable(0, 0)
# 建立组件
lb1 = tk.Label(win, text = '输入数据')
lb2 = tk.Label(win, text = '年平均降水量变化最大的年份区间是')
txt1 = tk.Entry(win,width=40)
txt1.insert(0,'1,11,19,18,0,16,8,9,17,4' )
txt2 = tk.Entry(win,width=20)
cmd = tk.Button(win, text = '找最大差值', command = findMax)

# 组件布局
lb1.grid(row=0, column=0)
lb2.grid(row=1, column=0,columnspan=2)
txt1.grid(row=0, column=1,columnspan=3)
txt2.grid(row=1, column=2)
cmd.grid(row=2,column=1)


# 接收窗口事件
win.mainloop()
